<script setup>
import { ref } from 'vue'
import { getUserPostService } from '@/apis/post.js'
import { onLoad } from '@dcloudio/uni-app'
import { useUserStore } from '@/stores/index.js'
import { formatTime } from '@/utils/formatTime.js'
import WaterFallComponent from '@/components/WaterFallComponent/WaterFallComponent.vue'

const UserStore = useUserStore()

// 存储获取到的用户攻略数据
const list = ref([])

// 获取用户发布的攻略数据
const getUserPostData = async () => {
	// 获取用户ID
	const userID = UserStore.UserInfoList.user_id
	const res = await getUserPostService(userID)
	// 格式化发布时间
	res.data?.map((item) => (item.createdAt = formatTime(item.createdAt)))
	list.value = res.data
}

onLoad(() => {
	getUserPostData()
})
</script>
<template>
	<view class="container">
		<WaterFallComponent v-if="list && list.length !== 0" :list="list" :collect="false" type_key="post"></WaterFallComponent>
		<up-empty v-else textSize="20" width="250" height="250" icon="https://leyouhui-1327374532.cos.ap-beijing.myqcloud.com/Static/data.png"></up-empty>
	</view>
</template>

<style lang="scss" scoped></style>
